﻿Imports System.ComponentModel

Public Class MonthlyReport
	Implements IDisposable

	Dim db As New CongregationDataContainerLocal

	Dim _AllMonthlyRecords As New BindingList(Of MonthlyReportRecord)
	Public ReadOnly Property AllMonthlyRecords As BindingList(Of MonthlyReportRecord)
		Get
			Return _AllMonthlyRecords
		End Get
	End Property

	Public Sub New()
		'Using db As New CongregationDataContainerLocal
		Dim myMonthlyReports As New List(Of MonthlyReportRecord)

		Dim monthlyReports = db.MonthlyReportDatas.Select(Function(x) x.Month).Distinct

		For Each monthlyReport In monthlyReports
			myMonthlyReports.Add(New MonthlyReportRecord(monthlyReport))
		Next

		For Each myRecord In myMonthlyReports.OrderByDescending(Function(x) x.ReportMonth)
			_AllMonthlyRecords.Add(myRecord)
		Next
		'End Using
	End Sub

#Region "IDisposable Support"
	Private disposedValue As Boolean ' To detect redundant calls

	' IDisposable
	Protected Overridable Sub Dispose(disposing As Boolean)
		If Not Me.disposedValue Then
			If disposing Then
				' TODO: dispose managed state (managed objects).
				db.Dispose()
			End If

			' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below.
			' TODO: set large fields to null.
		End If
		Me.disposedValue = True
	End Sub

	' TODO: override Finalize() only if Dispose(ByVal disposing As Boolean) above has code to free unmanaged resources.
	'Protected Overrides Sub Finalize()
	'    ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
	'    Dispose(False)
	'    MyBase.Finalize()
	'End Sub

	' This code added by Visual Basic to correctly implement the disposable pattern.
	Public Sub Dispose() Implements IDisposable.Dispose
		' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
		Dispose(True)
		GC.SuppressFinalize(Me)
	End Sub
#End Region

End Class
